<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <div class="aui-title">出借</div>
    </header>
    <div class="aui-bar-nav-d"></div>


    <style>
        body {
            background: #fff;
        }
    </style>
    <!-- <ul class="licai-nav">
        <li class="active list_type" tapmode onclick="licai_list(1)" id="list_type1">理财体验</li>
        <li class="list_type" tapmode onclick="licai_list(2)" id="list_type2">智能理财</li>
        <li class="list_type" tapmode onclick="licai_list(3)" id="list_type3">优质债权</li>
        <li class="list_type" tapmode onclick="licai_list(4)" id="list_type4">债券转让</li>
    </ul> -->

    <div class="claims-t">
        <ul>
            <li class="active list_type" tapmode onclick="licai_list(1)" id="list_type1">新手体验</li>
            <li class="list_type" tapmode onclick="licai_list(2)" id="list_type2">智能投标</li>
            <li class="list_type" tapmode onclick="licai_list(3)" id="list_type3">优质债权</li>
            <li class="list_type" tapmode onclick="licai_list(4)" id="list_type4">债权转让</li>
        </ul>
    </div>

    <div id="list"></div>

</body>
<script type="text/template" id="template">
    <ul class="licai-hqlc licai-hqlc-list">
        {{~it:value:index}}
        <li>
            <div class="licai-hqlc-t">
                <p>新手体验</p>
                <span class="green">每日付息</span>
                <span class="red">短期收益</span>
            </div>
            <div class="licai-hqlc-d">
                <h2>{{=value.rate}}%</h2> 预期年化收益
            </div>
            <div class="licai-hqlc-d">
                <p>7天 15天 30天</p>
                投资周期
            </div>
            <i>推荐</i>
            <a tapmode onclick="syx_buy({{=value.id}})">立即抢购</a>
        </li>

        {{~}}
    </ul>
</script>

<script type="text/template" id="template_znlc">
    <ul class="licai-znlc licai-znlc-list">
        {{~it:value:index}}
        <li class="aui-row">
            <div class="licai-znlc-t">
                {{? value.intelligence==1}}
                <span class="green">锁定周期</span> {{??}} {{?}} {{? value.intelligence==1}}
                <span class="red">智能选投</span> {{??}} {{?}}
            </div>
            <div class="aui-col-xs-4">
                <h2>
              {{=value.rate}}%

          </h2>
                <p>预期年化收益</p>
            </div>

            <div class="aui-col-xs-4">
                {{?value.per == 1}} {{=value.time_limit}}天 {{??}} {{=value.time_limit}}个月 {{?}} {{? value.hot==1}}
                <img src="image/licai-znlc.png"> {{??}}{{?}}
                <p>投资期限</p>
            </div>
            {{?value.recommend == 1}}
            <i>推荐</i> {{??}} {{?}}
            <div class="aui-col-xs-4 buy">
                <a tapmode onclick="znlc_buy({{=value.id}})">立即抢购</a>
                <p>剩余{{=value.borrow_amount}}元</p>
            </div>
            {{? value.is_rec==1}}
            <i>推荐</i> {{??}}{{?}}
        </li>
        {{~}}
    </ul>
</script>

<script type="text/template" id="template_yyzq">
    <ul class="licai-yzzq licai-yzzq-list">
        {{~it:value:index}}
        <li class="off">
            <div class="licai-yzzq-l">
                <div class="licai-yzzq-l-t">
                    <h2>{{=value.name}}{{=value.deal_sn}}{{? value.is_hot==1}}
              <img src="image/licai-znlc.png">
              {{??}}{{?}}</h2>
                </div>
                <div class="licai-yzzq-l-d">
                    <div class="licai-yzzq-l-d-l">
                        <h2>{{=value.rate}}
                          <!-- {{? value.add_rate==0}}{{??}}<span>+{{=value.add_rate}}%</span>{{?}}</h2> 预期年化收益 --> {{? value.add_rate==0}}{{??}}<span></span>{{?}}</h2> 预期年化收益

                    </div>
                    <div class="licai-yzzq-l-d-r">
                        <p>{{=value.repay_time}}个月</p>
                        {{? value.loantype==0}}等额本息{{?? value.loantype==1}}每月付息，到期还本{{?? value.loantype==2}}到期还本息{{?? value.loantype==3}}先息后本{{??}}{{?}}
                    </div>
                </div>
            </div>
            <div class="licai-yzzq-r-no">
                <img src="image/licai-znlc-off-4.png">
            </div>
        </li>
        {{~}}
    </ul>
</script>

<script type="text/template" id="template_zqzr">
    <div class="claims licai-zqzr-list">
        <ul class="claims-search">
            <li>
                <p>期限：</p>
                <select id="sel1">
              <option value ="0">1-6个月</option>
              <option value ="1">1-12个月</option>
              <option value ="2">12-24个月</option>
              <option value ="3">24个月以上</option>
          </select>
            </li>
            <li>
                <p>剩余本金：</p>
                <select id="sel2">
              <option value ="0">100-30000</option>
              <option value ="1">30000-100000</option>
              <option value ="2">100000-3000000</option>
              <option value ="3">300000-500000</option>
              <option value ="4">500000以上</option>
          </select>
            </li>
            <li>
                <p>年化率：</p>
                <select id="sel3">
              <option value ="0">5%以下</option>
              <option value ="1">5%-7%</option>
              <option value ="2">7%-9%</option>
              <option value ="3">9%-11%</option>
              <option value ="4">11%-13%</option>
              <option value ="5">13%以上</option>
          </select>
            </li>
            <li>
                <button tapmode onclick="shaixuan();">筛选</button>
            </li>
        </ul>
        {{~it:value:index}}
        <div class="claims-item">
            <!-- <div class="claims-item-icon">推荐</div> -->
            <div class="claims-item-t">
                <p>
                    {{=value.name}}{{=value.deal_sn}}
                    <!-- <img src="image/licai-znlc.png" alt=""> -->
                </p>
                <span class="diy">折让{{=value.discoutMoney}}元</span>
            </div>
            <ul class="claims-item-d">
                <li>
                    <p>{{=value.yearRate}}%</p>
                    预期年化收益
                </li>
                <li>
                    <span>{{=value.prospectiveEarnings}}</span> 预期收益(元)
                </li>
                <li>
                    {{? value.transferStatus==1}}
                    <button tapmode onclick="zqzr_buy({{=value.transfer_load_id}})">立即投资</button> 剩余期限{{=value.howMuchDay}}天 {{?? value.transferStatus==2}}
                    <button style="background:#c0c0c0">已转让</button> {{??}} {{?}}
                </li>
            </ul>
        </div>
        {{~}}
    </div>
</script>


<script type="text/javascript">
    var n = '';
    var type = 1;

    apiready = function() {
        load_list();
        down_refresh();
        addObserver_life();
        addObserver_right();

    }


    // 下拉刷新
    function down_refresh() {

        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            page = 1;

            if (type == 1) {
                load_list();
            }
            if (type == 2) {
                load_list_znlc();
            }
            if (type == 3) {
                load_list_yyzq();
            }
            if (type == 4) {
                load_list_zqzr();
            }
        });
    }

    function addObserver(num) {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {
            if (num == 3) {
                load_list_yyzq(true);
            }
            if (num == 4) {

            }
        });
    }

    function addObserver_life() {
        api.addEventListener({
            name: 'swipeleft'
        }, function(ret, err) {
            // alert('向左轻扫');
            if (type == 4) {
                return;
            } else {
                num = type + 1;
                licai_list(num);
            }
        });
    }

    function addObserver_right() {
        api.addEventListener({
            name: 'swiperight'
        }, function(ret, err) {
            // alert('向右轻扫');
            if (type == 1) {
                return;
            } else {
                num = type - 1;
                licai_list(num);
            }
        });
    }

    function licai_list(num) {

        if (num == type) {
            return;
        }
        if (type == 3) {
            api.removeEventListener({
                name: 'scrolltobottom'
            });
        }

        if (num == 1) {
            type = 1;
            var n = '';
            $(".list_type").removeClass("active");
            $("#list_type1").addClass('active');
            $(".licai-znlc-list").remove();
            $(".licai-yzzq-list").remove();
            $(".licai-zqzr-list").remove();
            load_list();
        }
        if (num == 2) {
            type = 2;
            var n = '';
            $(".list_type").removeClass("active");
            $("#list_type2").addClass('active');
            $(".licai-hqlc-list").remove();
            $(".licai-yzzq-list").remove();
            $(".licai-zqzr-list").remove();
            load_list_znlc();
        }
        if (num == 3) {
            type = 3;
            var n = '';
            $(".list_type").removeClass("active");
            $("#list_type3").addClass('active');
            $(".licai-hqlc-list").remove();
            $(".licai-znlc-list").remove();
            $(".licai-zqzr-list").remove();
            load_list_yyzq();
            addObserver(3);
        }

        if (num == 4) {
            type = 4;
            var n = '';
            $(".list_type").removeClass("active");
            $("#list_type4").addClass('active');
            $(".licai-hqlc-list").remove();
            $(".licai-znlc-list").remove();
            $(".licai-yzzq-list").remove();
            load_list_zqzr();
            addObserver(4);
        }
    }


    function syx_buy(id) {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'syx_buy',
            url: './syx_buy.html',
            pageParam: {
                id: id
            }
        });

    };

    function znlc_buy(id) {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'znlc_buy',
            url: './znlc_buy.html',
            pageParam: {
                id: id
            }
        });

    };

    function zqzr_buy(id) {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'claims_details',
            url: './claims_details.html',
            pageParam: {
                id: id
            }
        });
    }

    function closeWin() {
        api.closeWin({});
    }

    function load_list(n) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        if (n) {
            page += 1;
        } else {
            page = 1;
        }
        api.ajax({
            url: webAddress + '/index.php?ctl=app_deal&act=deal_list&page=' + page,
            method: 'get',

        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                if (ret.status == 0) {
                    alert(ret.info);
                } else if (ret.status == 1) {
                    updateList(ret.balance.list, ret.balance.min_money);
                }
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });

    }

    function updateList(data, num) {

        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);
        // document.getElementById('num3').innerHTML = outputmoney(num).substr(0, outputmoney(num).length-3)+'元起投';
    }

    function load_list_znlc(n) {
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        if (n) {
            page += 1;
        } else {
            page = 1;
        }
        api.ajax({
            url: webAddress + '/index.php?ctl=app_deal&act=deal_list&page=' + page,
            method: 'get',

        }, function(ret, err) {
            if (ret) {
                if (ret.status == 0) {
                    alert(ret.info);
                } else if (ret.status == 1) {
                    for (var i = 0; i < ret.licai.list.length; i++) {
                        ret.licai.list[i].borrow_amount = outputmoney(ret.licai.list[i].borrow_amount);
                    }
                    updateList_znlc(ret.licai.list, ret.licai.min_money);
                }
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });

    }

    function updateList_znlc(data, num) {
        var template = $api.byId('template_znlc');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);
    }

    function load_list_yyzq(n) {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        if (n) {
            page += 1;
        } else {
            page = 1;
        }
        api.ajax({
            url: webAddress + '/index.php?ctl=app_deal&act=deal_list&page=' + page,
            method: 'get',

        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                if (ret.status == 0) {
                    alert(ret.info);
                } else if (ret.status == 1) {
                    updateList_yyzq(ret.deal.list, ret.deal.min_money);
                }
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });
    }

    function updateList_yyzq(data, num) {

        var template = $api.byId('template_yyzq');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        if (page == 1) {
            $api.html(list, html);
        } else {

            if (!data) {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(list, html);
        }
        api.parseTapmode();
    }

    function load_list_zqzr(n) {
        // alert(1);
        // $(".licai-zqzr-list").show();
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        if (n) {
            page += 1;
        } else {
            page = 1;
        }
        api.ajax({
            url: webAddress + '/index.php?ctl=deals&act=zhuanrang_app',
            method: 'get',

        }, function(ret, err) {
            if (ret) {
                // alert( JSON.stringify( ret ) );
                updateList_zqzr(ret);

                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });
    }

    function updateList_zqzr(data) {

        var template = $api.byId('template_zqzr');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        if (page == 1) {
            $api.html(list, html);
        } else {

            if (!data) {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(list, html);
        }
        api.parseTapmode();
    }

    function shaixuan() {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        var postA = $("#sel1").val();
        var postB = $("#sel2").val();
        var postC = $("#sel3").val();
        api.ajax({
            url: 'http://big-wealth.com/index.php?ctl=deals&act=screen_zhuanrang',
            method: 'post',
            data: {
                values: {
                    postA: postA,
                    postB: postB,
                    postC: postC,
                    is_mobile: 1
                },

            }
        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                if (ret == '') {
                    alert('没有数据！');
                }
                updateList_zqzr(ret);
                api.hideProgress();
            } else {
                // alert(2);
                alert(JSON.stringify(err.msg));
                api.hideProgress();
            }
        });

    }
</script>

</html>
